package com.guigu.buy.controller;

import com.guigu.buy.pojo.SysMenu;
import com.guigu.buy.pojo.SysUser;
import com.guigu.buy.service.ISysMenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.awt.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Controller
@CrossOrigin
@RequestMapping("/buy/sysMenu")
public class SysMenuController {
    @Autowired
     private ISysMenuRoleService iSysMenuRoleService ;
    @RequestMapping("/getmenu")
    @ResponseBody
    public List<Map<String,Object>> getMenus(@RequestBody SysUser user){
        List<SysMenu> menuList = iSysMenuRoleService.getMenuList(user.getLoginName(),user.getPassword());
        List<Map<String,Object>> list = new ArrayList<>();
        if (menuList.size()>0){
            for(SysMenu menu:menuList){
                Map<String,Object> map = new LinkedHashMap<>();
                map.put("id",menu.getId());
                map.put("menuName",menu.getName());
                map.put("iamge_url",menu.getIamgeUrl());
                map.put("children",iSysMenuRoleService.gettwoMenuList(user.getLoginName(),user.getPassword(),menu.getId()));
                list.add(map);
            }
        }
        return list;
    }


}
